#include "enemy_10_normal.h"

extern int G_H,G_W;

ENEMY_10_NORMAL::ENEMY_10_NORMAL(QPoint p, SCENE *scene, QTimeLine *global_tl, CASH *cash):QGraphicsObject()
{

    go = new SOUND_POWER(cash,"Res/Sound/Enemy/Enemy_10/Normal.ogg",this);
    go->Play_Now();

    point=10000;

    border = cash->cash_poly->value("Res/Ships/Enemy/Enemy_10/Enemy_10_normal/Enemy_10_normal.poly");
    im = cash->cash_pixmap->value("Res/Ships/Enemy/Enemy_10/Enemy_10_normal/Enemy_10_normal.png");

    this->setZValue(0.5);

    this->setPos( QPointF( p.x()-60,p.y()+100) );

    anim_enemy = new QGraphicsItemAnimation();

    enemy_time_line = new QTimeLine(10000);                                             // Скорость перемещения обьекта по траектории
    enemy_time_line->setEasingCurve( QEasingCurve::Type(9));

    enemy_time_line->setFrameRange(0, 1);
    anim_enemy->setTimeLine(enemy_time_line);
    anim_enemy->setItem(this);

    anim_enemy->setPosAt(0,QPointF( p.x()-60,p.y()+100) );
    anim_enemy->setPosAt(0.5,QPointF( p.x()-60,p.y()-150) );
    anim_enemy->setPosAt(0.7,QPointF( p.x()-60,p.y()-150) );
    anim_enemy->setPosAt(0.8,QPointF( p.x()-60,p.y()-150) );
    anim_enemy->setPosAt(0.9,QPointF( p.x()-60,p.y()-150) );
    anim_enemy->setPosAt(1,QPointF( p.x()-60,p.y()+100) );

    enemy_time_line->start();

    collisia_control = new COLLISIA_CONTROL(scene,((QGraphicsObject*)this),this,global_tl,cash,100);

    connect(collisia_control,SIGNAL(Collisia(QPointF,int)),this,SLOT(Damage_Detected(QPointF,int)));
    connect(enemy_time_line,SIGNAL(finished()),SLOT(deleteLater()));

}

QPainterPath ENEMY_10_NORMAL::shape() const
{

    return *border;

}

QRectF ENEMY_10_NORMAL::boundingRect() const
{

    return QRectF( QPointF(0,0),im->size() );

}

void ENEMY_10_NORMAL::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{

    painter->save();
    painter->drawPixmap( 0,0,*im );
    painter->restore();

}

ENEMY_10_NORMAL::~ENEMY_10_NORMAL()
{
    go->Stop();
}

int ENEMY_10_NORMAL::type() const
{

    return point;

}

void ENEMY_10_NORMAL::Damage_Detected(QPointF a, int d)
{

    a = QPointF();
    point-=d;

    if(point<=0)
        if(this->scene()){
            disconnect(enemy_time_line,SIGNAL(finished()),this,SLOT(deleteLater()));
            go->Stop();
            emit Kill_Me_Please((QGraphicsObject*)this);
        }

}




